/**
 * Created by sioxa on 2016/12/25 0025.
 */
import Vue from 'vue'
import API from '../config/api'

function extendObj (url,def, obj) {
  console.log(url)
	var new_obj = new Object();
	var unsetArr = new Array();
	if(typeof(obj) != 'object' && obj == null){
    if(typeof(def["params"])=='undefined'){
      def.params={};
    }
    def["params"]["uid"]=sessionStorage.uid;
		return def;
	}else{
		for( var i in def ){
			new_obj[i] = obj[i]?obj[i]:def[i];
		}

		for( var j in obj ){
			if(!new_obj[j])
			new_obj[j] = obj[j];
		}
    if(typeof(new_obj["params"])=='undefined'){
      new_obj.params={};
    }
    new_obj["params"]["uid"]=sessionStorage.uid;
	}
	return new_obj;
}

function apiFactory(api){
  return (options) => Vue.http[api.type](
    api.url,
    extendObj(api.url,api.params(), options)
  )
}


export default {
  actions: {
  	getUerLogin({},id){
  		return apiFactory(API.getUerLogin)()
  	},
    
    getFormContent({},options){
      return apiFactory(API.getFormContent)(options)
    },
  }
}
